<?php
	require_once('../app.php');
	$dbAccounts = Db::getModel('accounts');
	$dbComplaints = Db::getModel('complaints');
	$dbNews = Db::getModel('News');
	
	$str = <<<HEREDOC
<?xml version="1.0" encoding="UTF-8"?>
<urlset
		xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
   	 	http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">

<url>
	<loc>http://www.consumerprotectionagency.org/</loc>
</url>
<url>
	<loc>http://www.consumerprotectionagency.org/login</loc>
</url>
<url>
	<loc>http://www.consumerprotectionagency.org/signup</loc>
</url>
<url>
	<loc>http://www.consumerprotectionagency.org/complaints/post</loc>
</url>
<url>
	<loc>http://www.consumerprotectionagency.org/complaints/browse</loc>
</url>
<url>
	<loc>http://www.consumerprotectionagency.org/comments/browse</loc>
</url>
<url>
	<loc>http://www.consumerprotectionagency.org/companies/browse/title_up</loc>
</url>
<url>
	<loc>http://www.consumerprotectionagency.org/about</loc>
</url>
<url>
	<loc>http://www.consumerprotectionagency.org/terms_conditions</loc>
</url>
<url>
	<loc>http://www.consumerprotectionagency.org/faq</loc>
</url>
<url>
	<loc>http://www.consumerprotectionagency.org/news</loc>
</url>
HEREDOC;


//Complaints
$complaints = $dbComplaints->findByFull(array("status"=>"='active'"));

foreach($complaints as $key=>$var){
	$str .="<url>\n";
		$str .= "\t<loc>http://www.consumerprotectionagency.org/complaint/view/".$var[id]."/"._replace(htmlspecialchars($var['title']))."</loc>\n";
	$str .= "</url>\n";
}

//News
$news = $dbNews->findByFull(array("status"=>"='active'"));

foreach($news as $key=>$var){
	$str .="<url>\n";
		$str .= "\t<loc>http://www.consumerprotectionagency.org/news/view/".$var[id]."/"._replace(htmlspecialchars($var['title']))."</loc>\n";
	$str .= "</url>\n";
}

//Personts
$persons = $dbAccounts->findByFull(array("status"=>"='active'","utype"=>"='member'"));

foreach($persons as $key=>$var){
	$str .="<url>\n";
		$str .= "\t<loc>http://www.consumerprotectionagency.org/person/view/".$var[id]."/"._replace(htmlspecialchars($var['fname']." ".$var['lname']))."</loc>\n";
	$str .= "</url>\n";
}



$str .="\n</urlset>";

file_put_contents("sitemap.xml",$str,FILE_APPEND);

?>